﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Mesuro.Graphing {
	public struct Circ {
		private Point _centre;
		/// <summary>
		/// Gets/sets the centre point of this circle.
		/// </summary>
		public Point Centre {
			get { return _centre; }
			set { _centre = value; }
		}

		private double _radius;
		/// <summary>
		/// Gets/sets the radius of this circle.
		/// </summary>
		public double Radius {
			get { return _radius; }
			set { _radius = value; }
		}

		/// <summary>
		/// Gets/sets the diamter of this circle.
		/// </summary>
		public double Diameter {
			get { return 2 * _radius; }
			set { _radius = value / 2; }
		}

		/// <summary>
		/// Gets the minimum enclosing rectangle. This will always be square.
		/// </summary>
		public Rect BoundingSquare {
			get {
				return new Rect( _centre.X - _radius, _centre.Y - _radius,
					2 * _radius, 2 * _radius );
			}
		}
		public double Left {
			get { return Centre.X - Radius; }
		}
		public double Top {
			get { return Centre.Y - Radius; }
		}
		public double Right {
			get { return Centre.X + Radius; }
		}
		public double Bottom {
			get { return Centre.Y + Radius; }
		}

		public Point LeftPt {
			get { return new Point( Centre.X - Radius, Centre.Y ); }
		}
		public Point TopPt {
			get { return new Point( Centre.X, Centre.Y - Radius ); }
		}
		public Point RightPt {
			get { return new Point( Centre.X + Radius, Centre.Y ); }
		}
		public Point BottomPt {
			get { return new Point( Centre.X, Centre.Y + Radius ); }
		}

		/// <summary>
		/// Creates a circle with a specified centre and radius.
		/// </summary>
		/// <param seriesKey="centre">The centre point of the circle.</param>
		/// <param seriesKey="radius">The radius of the circle.</param>
		public Circ( Point centre, double radius )
			: this() {
			_radius = radius;
			_centre = centre;
		}

		/// <summary>
		/// Creates the largest possible fully inscribed circle centred within the bounds of the rectangle
		/// </summary>
		/// <param seriesKey="bounds">Rectangle in inscribe with circle</param>
		public Circ( Rect bounds )
			: this() {
			_radius = Math.Min( bounds.Width, bounds.Height ) / 2;
			_centre.X = bounds.X + _radius;
			_centre.Y = bounds.Y + _radius;
		}

		/// <summary>
		/// Creates a circle with a diameter equal to the lesser of the height and width of the supplied Size object.
		/// </summary>
		/// <param seriesKey="size">Maximum size of the circle to create.</param>
		public Circ( Size size )
			: this() {
			_radius = Math.Min( size.Width, size.Height ) / 2;
			_centre.X = _radius;
			_centre.Y = _radius;
		}


	}
	public static class CircExt {
		public static void DrawEllipse( this DrawingContext dc, Brush fill, Pen outline, Circ circle ) {
			dc.DrawEllipse( fill, outline, circle.Centre, circle.Radius, circle.Radius );
		}
	}
}
